<template>
    <div>
    <HomeView></HomeView>
    <div class="order">


        <el-table
            :data="table"
            style="width: 100%">
            <el-table-column
        
                prop="orderKey"
                label="订单号"
                width="180">
            </el-table-column>
            <el-table-column
        
                prop="date"
                label="日期"
                width="180">
            </el-table-column>
            <el-table-column
            
                prop="cname"
                label="用户名"
                width="180">
            </el-table-column>
            <el-table-column
            
                prop="phone"
                label="手机号"
                width="180">
            </el-table-column>
            <el-table-column
            
                prop="address"
                label="取车地址"
                width="150">
            </el-table-column>
            <el-table-column
            
                prop="carKey"
                label="车辆号"
                width="90">
            </el-table-column>
            <el-table-column
            
                prop="time"
                label="租车天数">
            </el-table-column>
            <el-table-column

                prop="amount"
                label="金额">
            </el-table-column>
            <el-table-column

                prop="custKey"
                label="顾客号">
            </el-table-column>
            <el-table-column
                prop="status"
                label="状态">
                </el-table-column>
            <el-table-column
                    fixed="right"
                    label="操作"
                    width="100">
                    <template slot-scope="scope">
                        <el-button @click="update(scope.row.id)" type="text" size="small">退款</el-button>
                    </template>
                    </el-table-column>
            <!-- <el-button style="float: right; padding: 3px 0" type="text" @click="Naw">刷新</el-button> -->
            </el-table>



    </div>
</div>


</template>

<script>
import HomeView from '@/views/HomeView.vue'
export default{
    data(){
        return {
            table:[]
        }
    },

    methods:{
    
        update(id){
            var order= this.table[id].orderKey
            this.$axios.post('/orders/updateOrders',{
                orderKey:order,
                status:2
                
            },{
                headers:{
                    "token":JSON.parse(localStorage.getItem('user')).token
                }
            })
            .then(res=>{
                if(res.data.msg=="success"){
                    alert("已申请退款")
                }
                this.$router.go(0)
            })
        }
    },
    components:{
        HomeView
    },
    created(){

        this.$axios.post('/orders/selectCustKey',{
            custKey:JSON.parse(localStorage.getItem('user')).custKey
        },
        {
              headers:{
                "token":JSON.parse(localStorage.getItem('user')).token
              } 
              })
        .then(response =>{
                this.form = response.data.data;
                this.table = this.form
                console.log(this.table)
                for(let i = 0; i<this.table.length;i++){
                    this.table[i].cname = JSON.parse(localStorage.getItem('user')).cname
                    this.table[i].phone = JSON.parse(localStorage.getItem('user')).phone
                    this.table[i].address = JSON.parse(localStorage.getItem('user')).address
                    this.table[i].id = i
                }
                for(let i=0;i<this.table.length;i++){
                      this.table[i].id = i
                      if(this.table[i].status==1){
                          this.table[i].status = "已提交"
                        }
                        else if(this.table[i].status==0){
                          this.table[i].status = "已通过"
                        }
                        else if(this.table[i].status==2){
                          this.table[i].status = "申请退款"
                        }
                    }
            })
    }

}
</script>

<style>
  .text {
    font-size: 14px;
  }

  .item {
    margin-bottom: 18px;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both
  }

  .box-card {
    width: 480px;
  }
</style>